<template>
    <div class="taik">
        <button @click="getLoveTalk">获取一句土情话</button>
        <ul>
            <li v-for='talk in talkStore.talkList' :key="talk.id">{{ talk.title }}</li>
        </ul>
    </div>
</template>

<script lang="ts" setup name="LoveTail">
    import axios from 'axios'
    import { reactive } from 'vue'
    import { nanoid } from 'nanoid'
    import { useLoveTalkStore } from '../store/loveTalk.ts'

    const talkStore = useLoveTalkStore()
    // let taikList = reactive([
    //     {id:'lsjfglkjh01',title:'张三'},
    //     {id:'lsjfglkjh02',title:'李四'},
    //     {id:'lsjfglkjh03',title:'王五'}
    // ])

    // 方法
    // 土味情话 https://api.uomg.com/api/rand.qinghua?format=json
    async function getLoveTalk(){
        talkStore.getAtalk()
    }

    talkStore.$subscribe((mutate,state)=>{
        console.log('talkStore里面保存的数据发生了变化',mutate,state)
        localStorage.setItem('talkList',JSON.stringify(state.talkList))
    })
</script>

<style scoped>
    .taik{
        margin-top:20px;
        background-color: orange;
        padding:10px;
        border-radius: 10px;
        box-shadow: 0 0 10px;
    }
</style>